package models

import (
	"encoding/json"
	"server-admin-api/views"
	"time"
)

type Group struct {
	Id      uint      `gorm:"primaryKey;autoIncrement" json:"id"` // 主键
	Title   string    `gorm:"size:100" json:"title"`              // 服务名称
	Desc    string    `json:"desc"`                               // 描述
	UpTime  time.Time `json:"up_time"`
	AddTime time.Time `json:"add_time"`
}

func (g Group) MarshalJSON() ([]byte, error) {
	type temp Group
	return json.Marshal(&struct {
		temp
		UpTime  DateTime `json:"up_time"`
		AddTime DateTime `json:"add_time"`
	}{
		temp:    (temp)(g),
		UpTime:  DateTime(g.UpTime),
		AddTime: DateTime(g.AddTime),
	})
}

func (g Group) NewBuild(param views.GroupCreate) Group {
	return Group{
		Title: param.Title,
		Desc: param.Desc,
		UpTime:   time.Now(),
		AddTime:  time.Now(),
	}
}
